package www.yfz.servlet;

import java.io.IOException;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import www.yfz.service.UserService;
@WebServlet("/hello")
public class Servlet extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = -6100843975983620557L;
	String driver ="com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://localhost:3306/mysql";
    String username = "root";
    String password = "root";


	@Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	// TODO Auto-generated method stub
		/*
		 * 获取前段传递的数据
		 * */
    	String username=request.getParameter("username");
    	String password=request.getParameter("password");
    	System.out.println(username+","+password);
    	/*
    	 * 调用Service
    	 * */
    	UserService service=new UserService();
    	boolean rs=service.login(username, password);
    	/*
    	 * 根据判断跳转不同的页面
    	 * */
    	if(rs){
    		System.out.println("登陆成功");
    		request.getRequestDispatcher("success.jsp").forward(request, response);
    	}else{
    		System.out.println("登陆失败");
    		request.getRequestDispatcher("error.jsp").forward(request, response);
    	}
    	
    }
}
